#pragma once
#include "CMulticoreTask.h"



#include "CRasterizeBandParams.h"

class CMulticoreTaskScheduler;
class CRasterizerEdgeStore;
class CColorBuffer;
class CLayer;
class CAntialiasedFiller;
class CActiveEdge;


class CBandVectorBuffer :
	public CMulticoreTask
{

public: 
	static HRESULT Create(XINT32 offsetX, XINT32 offsetY, XINT32 width, XUINT32 startY, XUINT32 endY, XUINT32 clearTypeEnabled, CBandVectorBuffer * * ppVectorBuffer);
	~CBandVectorBuffer();
	XINT32 GetWidth();
	XINT32 GetOffsetX();
	HRESULT RasterizeBand(XUINT32 nCPUCore, struct ArgbPixel dwBackgroundColor, enum PixelFormat pixelFormat, XUINT32 nWidth, XUINT32 nHeight, XINT32 nStartY, XINT32 nEndY, XUINT8 * pFillBits, XUINT8 * pStrokeBits, XUINT32 uStride, XUINT32 cbBufferSize, XUINT32 fFullRedraw, XUINT32 fEnableDirtyRegionsDisplay, struct XRECT_WH * prcDirtyRect);
	HRESULT RasterizeBandOffThread(CMulticoreTaskScheduler * pScheduler, struct ArgbPixel dwBackgroundColor, enum PixelFormat pixelFormat, XUINT32 nWidth, XUINT32 nHeight, XINT32 nStartY, XINT32 nEndY, XUINT8 * pFillBits, XUINT8 * pStrokeBits, XUINT32 uStride, XUINT32 cbBufferSize, XUINT32 fFullRedraw, XUINT32 fEnableDirtyRegionsDisplay, struct XRECT_WH * prcDirtyRect);
	HRESULT GetRenderingResult(struct XRECT_WH * prcDirtyRect);
	HRESULT CompleteRendering(CRasterizerEdgeStore * pRasterizerEdgeStore);
	void CleanupUnrasterizedPaths();

private: 
	CBandVectorBuffer();
	HRESULT Init(XINT32 nOffsetX, XINT32 nOffsetY, XINT32 nWidth, XUINT32 nStartY, XUINT32 nEndY, XUINT32 clearTypeEnabled);
	void Reset();
	HRESULT AdvanceScanline(XINT32 * pnStartXDirty, XUINT32 * pcDirtyPixels);
	static HRESULT PrepareRasterizerData(CBandVectorBuffer * pBandBuffer, CRasterizerEdgeStore * pRasterizerEdgeStore, struct RasterizerData * pRasterizerData);
	void ReleasePendingPaths();
	static HRESULT DrawVirtualLayer(XUINT32 nCPUCore, CColorBuffer * pColorBuffer, CLayer * pLayer);
	HRESULT AllocActiveLayerData(XINT32 nWidth, struct CActiveLayerData * * ppActiveLayer);
	void FreeActiveLayerData(struct CActiveLayerData * pActiveLayer);
	static HRESULT FreeRasterizerData(CBandVectorBuffer * pBandBuffer, CRasterizerEdgeStore * pRasterizerEdgeStore, struct RasterizerData * pRasterizerData);
	virtual HRESULT Run(XUINT32 nCPUCore);
	HRESULT RasterizeBandForShapeMask(CRasterizerEdgeStore * pEdgeStore, CAntialiasedFiller & filler, XINT32 nSubpixelYCurrent, XINT32 nSubpixelYNext, XUINT8 * pFillRow, XUINT8 * pStrokeRow, XINT32 outputRowWidth);
	CRasterizerEdgeStore * * m_pVectorBuffer;
	XINT32 m_nOffsetX;
	XINT32 m_nSubpixelOffsetX;
	XINT32 m_nOffsetY;
	XINT32 m_nStartY;
	XINT32 m_nEndY;
	XINT32 m_nWidth;
	XINT32 m_nCurrentScanline;
	CRasterizerEdgeStore * m_pCurrentPathList;
	CRasterizerEdgeStore * m_pPreviousFramePaths;
	CRasterizerEdgeStore * m_pPathsToRelease;
	struct RasterizerData * m_pRasterizerDataPool;
	struct CActiveLayerData * m_pActiveLayerPool;
	CActiveEdge * m_pFreeActiveEdgePool;
	struct CRasterizeBandParams m_rasterizeParams;
	XUINT32 m_nDirtyFrameNumber;
	XUINT32 m_clearTypeEnabled;


};